from pathlib import Path
from datetime import datetime

def format_filesize(n_byte:int) -> str:
    if n_byte < 1024: return f"{n_byte}B"
    elif n_byte < 1048576: return f"{n_byte//1024}KB"
    else: return f"{(n_byte/1048576):.04}MB"

def format_filetitle(path:str) -> str:
    path = Path(path)
    stat = path.stat()
    filesize = format_filesize(stat.st_size)
    time_last_modify = datetime.fromtimestamp(stat.st_mtime)
    str_time_last_modify = f"{time_last_modify.year}-{time_last_modify.month:02}-{time_last_modify.day:02}"
    return f"[{filesize}|{str_time_last_modify}] {path.name}"
